package com.javasm.sys;

import com.javasm.commons.util.ServletUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;


@Component
public class CurrentLogin {
    public static SysUser getLoginUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Object principal = authentication.getPrincipal();

        if(principal!=null){
            LoginUser u = (LoginUser)principal;
            return u.getUser();
        } else{
           return null;
        }
    }

    public static String getLoginUserName(){
        SysUser loginUser = getLoginUser();

        if(loginUser==null)return null;
        return loginUser.getUserName();
    }
}
